package com.example.leero.graduation.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.leero.graduation.R;

/**
 * Created by Leero on 2017-6-4.
 */

public class FavourSportAdapter extends BaseAdapter {

    private String[] list;
    private Context context;
    private Boolean[] selections;

    public FavourSportAdapter(Context context, String[] data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.length;
    }

    @Override
    public Object getItem(int position) {
        return list[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setSelected(Boolean[] selection) {
        this.selections = selection;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_screen_text, null);
            viewHolder.tv_item_screen = (TextView) view.findViewById(R.id.tv_item_screen);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.tv_item_screen.setText(list[position]);
        if (selections[position]) {
            viewHolder.tv_item_screen.setTextColor(Color.parseColor("#ff45bb62"));
        } else {
            viewHolder.tv_item_screen.setTextColor(Color.parseColor("#ff767676"));
        }

        return view;
    }

    public class ViewHolder {
        TextView tv_item_screen;
    }
}
